"""Build blob I/O"""

FILES = ['bio_buffer.c', 'bio_bulk.c', 'bio_config.c', 'bio_context.c', 'bio_device.c',
         'bio_monitor.c', 'bio_recovery.c', 'bio_xstream.c', 'bio_wal.c', 'smd.pb-c.c']


def scons():
    """Execute build"""
    Import('env', 'prereqs', 'control_tgts')

    env.AppendUnique(LIBPATH=[Dir('.')])
    env.AppendUnique(LIBPATH=[Dir('smd')])

    if not prereqs.server_requested():
        return

    denv = env.Clone()
    denv.AppendUnique(LINKFLAGS=["-Wl,--no-as-needed"])
    denv.Append(CPPDEFINES=['-DDAOS_PMEM_BUILD'])
    denv.require('pmdk', 'spdk', 'argobots', 'protobufc')

    SConscript('smd/SConscript')
    denv.AppendUnique(OBJPREFIX='b_')

    # SPDK related libs
    libs = ['spdk_log', 'spdk_env_dpdk', 'spdk_thread', 'spdk_bdev', 'rte_mempool']
    libs += ['rte_mempool_ring', 'rte_bus_pci', 'rte_pci', 'rte_ring']
    libs += ['rte_mbuf', 'rte_eal', 'rte_kvargs', 'spdk_bdev_aio']
    libs += ['spdk_bdev_nvme', 'spdk_blob', 'spdk_nvme', 'spdk_util']
    libs += ['spdk_json', 'spdk_jsonrpc', 'spdk_rpc', 'spdk_trace']
    libs += ['spdk_sock', 'spdk_log', 'spdk_notify', 'spdk_blob_bdev']
    libs += ['spdk_vmd', 'spdk_event_bdev', 'spdk_init']

    # Other libs
    libs += ['numa', 'dl', 'smd']

    tgts = FILES + control_tgts
    bio = denv.d_library("bio", tgts, install_off="../..", LIBS=libs)
    denv.Install('$PREFIX/lib64/daos_srv', bio)


if __name__ == "SCons.Script":
    scons()
